home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / java drawing / src / javapainter.java < prev   
Encoding:
Java Source  |  2000-06-23  |  1.9 KB  |  67 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.io.*;
  10. import quicktime.app.image.*;
  11.  
  12. class JavaPainter implements Paintable {
  13.     
  14.     JavaPainter (Frame f, String iName) {
  15.         this.f = f;
  16.         this.iName = iName;
  17.     }
  18.     
  19.     Frame f;
  20.     String iName;
  21.     Image im;
  22.     Font font = new Font ("Helvetica", Font.PLAIN, 18);
  23.     int width, height;
  24.     Rectangle[] r = new Rectangle[1];
  25.     
  26.     void prepareImage () throws Exception {
  27.         MediaTracker tracker = new MediaTracker (f);
  28.         im = Toolkit.getDefaultToolkit().getImage(iName);
  29.         tracker.addImage (im, 0);
  30.         
  31.         // wait for them all to finish importing
  32.         try { tracker.waitForAll(); }
  33.         catch (InterruptedException e) { }
  34.         
  35.         if (tracker.isErrorAny()) throw new Exception ("Error in Media Tracker");
  36.  
  37.         // make sure images are prepared so they draw properly
  38.         f.prepareImage (im, f);
  39.     }
  40.  
  41.     public void newSizeNotified (QTImageDrawer drawer, Dimension d) {
  42.         width = d.width;
  43.         height = d.height;
  44.         r[0] = new Rectangle (width, height);
  45.     }
  46.     
  47.     /**
  48.      * Paint on the graphics. The supplied component is the component from which
  49.      * the graphics object was derived or related to and is also the component
  50.      * that is the object that paint was called upon that has called this method.
  51.      * The Graphics object is what you should paint on.
  52.      * This maybe an on or off screen graphics.
  53.      * You should not cache this graphics object as it can be different
  54.      * between different calls.
  55.      * @param comp the component from which the Graphics object was derived or 
  56.      * related too.
  57.      * @param g the graphics to paint on.
  58.      */
  59.     public Rectangle[] paint (Graphics g) {        
  60.         g.drawImage (im, 0, 0, null);
  61.         g.setColor (Color.red);
  62.         g.setFont (font);
  63.         g.drawString ("Hello! I'm the Duke.", 2, height - 2);
  64.         return r;
  65.     }
  66. }
  67.